<?php
apf_require_controller("QaAbstract");

class Qa_Finance_IndexController extends QaAbstractController {

    private $desc_list = array(
        Const_Qa::TAG_FINANCE_BIAODAN=>"常见的财务表单下载",
        Const_Qa::TAG_FINANCE_BAOXIAO=>"关于财务报销/付款的常见问题",
        Const_Qa::TAG_FINANCE_FAPIAO=>"关于财务发票的常见问题",
        Const_Qa::TAG_FINANCE_HETONG=>"关于财务合同的常见问题",
        Const_Qa::TAG_FINANCE_LIUCHENG=>"关于财务操作流程的常见问题",
        Const_Qa::TAG_FINANCE_KAIPIAO=>"关于财务公司开票信息的常见问题",
        Const_Qa::TAG_FINANCE_ZHIDU=>"关于财务参考制度的常见问题",
        Const_Qa::TAG_FINANCE_LIANXI=>"关于财务联系我们的常见问题",
        Const_Qa::TAG_FINANCE_CHANGSHI=>"关于财务常识的常见问题",
    );


    public function handle_request(){
        $params = $this->request->get_parameters();
        $cate = empty($params['cate']) ? 1 : $params['cate'];
        //获取所有数据
        $total = $this->get_question_bll()->get_question_list(Const_Qa::TAG_FINANCE, $cate, false, $cate != Const_Qa::TAG_FINANCE_BIAODAN, null, null);

        $this->page_num = $params['p'];
        //计算总页数
        $page_total = ceil(count($total) / $this->page_rows);
        if($this->page_num < 1){
            $this->page_num = 1;
        }elseif($this->page_num > $page_total){
            $this->page_num = $page_total;
        }

        $list = array();
        if(!empty($total)){
            $list = array_slice($total, ($this->page_num - 1) * $this->page_rows, $this->page_rows);
        }
        $tag = Const_Qa::get_menu_list_en(Const_Qa::TAG_FINANCE);
        $this->request->set_attribute('multipage', $this->_get_page($total, $this->page_num, $params));
        $this->request->set_attribute('list', $list);
        $this->request->set_attribute('left_list', Const_Qa::get_left_list_id(Const_Qa::TAG_FINANCE));
        $this->request->set_attribute('cate', $cate);
        $this->request->set_attribute('page_num', $this->page_num);
        $this->request->set_attribute('page_rows', $this->page_rows);
        $this->request->set_attribute('permission', $_SESSION[$tag]);
        return "Qa_Finance_Index";
    }

    /**
     * 获取分页
     * Enter description here ...
     */
    private function _get_page($total,$curr_page,$param){
        $_where['p'] = $curr_page;
        $_where['cate'] = $param['cate'];
        $url_suffix = "";
        $url_prefix = "";
        if(count($total) > $this->page_rows){
            $result = Util_MultiPage::multiPage($url_prefix, $_where, $url_suffix, count($total), $this->page_rows, 10 , false, true);
        }
        return $result ;
    }
}